<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Coursity.net</title>
        <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
        <script type="text/javascript" src="js/global.js"></script>
        <script type="text/javascript" src="js/adress_bar.js"></script>
        <style>
        	.alert{color:red; font-weight:bold;}
        	.course_div, .course_div_top{border-bottom:1px dashed black; padding:10px;}
        	.course_div:hover{padding-left:12px; background-color:#FFFFCC}
        </style>
        <script>
			var cid;
			
            $(document).ready(function(){
            	cid = $.QueryString['cid'];
            	var iid = $.QueryString['iid'];
            	var service;
            	
            	switch(cid){
            		case '1':
            			service = 'initiative/listCourses';
            			break;
            		case '2':
            			service = 'instructor/listCourses';
            			break;	
            		case '3':
            			service = 'institution/listCourses';
            			break;	
            	}
            	
            	var servicex = '';
                $.post('/Coursity/'+service, {id:iid}, function(result){
                	
                	var tmp, tmp2, xheader;
                	
                	switch(cid){
            		case '1':
            			service = 'initiative/listCourses';
            			tmp = result.body[0].initiative.initiativeName;
            			tmp2 = tmp.split('(');
            			xheader = tmp2[0];
            			break;
            		case '2':
            			service = 'instructor/listCourses';
            			xheader = result.body[0].instructor.instructorName;
            			break;	
            		case '3':
            			service = 'institution/listCourses';
            			xheader = result.body[0].institution.institutionName
            			break;	
            		}
                	
                	$('h1').html('The courses of ' + xheader);
                	if(result.body.length>0){
	                	for(var i=0; i<result.body.length; i++){
	                		servicex += '<div class="course_div">';
	                		servicex += '<h2>' + result.body[i].courseName + '</h2>';
	                		servicex += '<b>Starting Date:</b> ' + result.body[i].startingDate + '<br />';
	                		servicex += '<b>Course Description:</b> ' + result.body[i].courseDescription + '<br />';
	                		servicex += '<b>Estimated Efforts:</b> ' + result.body[i].estimatedEffort + '<br />';
	                		servicex += '<b>Institution:</b> ' + result.body[i].institution.institutionName + '<br />';
	                		servicex += '<b>Instructor:</b> ' + result.body[i].instructor.instructorName + '<br />';
	                		servicex += '<b>Languages:</b> ' + result.body[i].languages + '<br />';
	                		servicex += '<b>Length:</b> ' + result.body[i].length + '<br />';
	                		servicex += '<b>Country:</b> ' + result.body[i].country + '<br />';
	                		servicex += '<b>Recommended Background:</b> ' + result.body[i].recommendedBackground + '<br />';
	                		servicex += '<a href="course_details.html?cid=' + result.body[i].courseId + '">Details of this course</a>';
	                		servicex += '</div>';
	                	}
	                }
                	else{
                		servicex = '<span class="alert">There is no course found for your criteria</span>';
                	}
                	$('#search_results').html('<div class="course_div_top"></div>' + servicex);
                	
                }, 'json');	
            });
        </script>
    </head>
    <body>
        <h1></h1>
        <p><a href="index.html">< back to main page</a></p>
        <div id="search_results"></div>
    </body>
</html>